package com.gitee.wsl.compose.chart.xy.bar.bullet.model

import androidx.compose.runtime.Composable

/**
 * A scope for setting range boundaries. See [range] for specifying a specific range value and its graphical
 * representation.
 */
class RangesScope<T> {
    internal val ranges: MutableList<Range<T>> = mutableListOf()

    /**
     * Defines a new qualitative range that begins at the end of the previous range's value
     * and extends until [endValue]. The default indicator will be drawn as a shaded bar
     * depending on this range's position among all ranges and the number of ranges, but can
     * be overridden by providing a non-null value for [indicator]. The shading is a percentage of
     * the material theme primary color for the following numbers of ranges:
     * One: 35%
     * Two: 35% and 10%
     * Three: 40%, 25%, and 10%
     * Four: 50%, 35%, 20%, and 10%
     * Five: 50%, 35%, 20%, 10%, and 3%
     * Sixth and higher ranges are shaded at 1%
     */
    fun range(endValue: T, indicator: (@Composable () -> Unit)? = null) {
        ranges.add(Range(endValue, indicator))
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other == null || this::class != other::class) return false

        other as RangesScope<*>

        if (ranges != other.ranges) return false

        return true
    }

    override fun hashCode(): Int {
        return ranges.hashCode()
    }
}